package com.flipdf2.serialize.ppml.element;

import org.jdom.Element;
import org.jdom.Namespace;

import com.flipdf2.serialize.ppml.PPMLException;

public class PPMLDatum {
	public static final String NAME = "DATUM";

	private String data;
	private String key;
	private String content;
	
	public Element toXML(Namespace defaultNamespace) {
		Element root = null;
		if (defaultNamespace != null) {
			root = new Element(NAME, defaultNamespace);
		} else {
			root = new Element(NAME);	
		}
	
		if (data != null && data.length() > 0)
			root.setText(data);
		if (key != null && key.length() > 0)
			root.setAttribute("Key", key);
		if (content != null && content.length() > 0)
			root.addContent(content);
		return root;
	}
	
	public void check() throws PPMLException {
		if (key == null) {
			throw PPMLException.getInstance(PPMLException.REQUIRED_ATTRIBUTE_LOST, "Key");
		}
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}
}
